1 00:00:00,590 --> 00:00:01,100 Hey there. 2 00:00:01,100 --> 00:00:05,120 In this lecture I want to go over the comparison operators in Lua. 3 00:00:05,240 --> 00:00:10,940 You already know three comparison operators greater than, less than and equal to. 4 00:00:10,940 --> 00:00:14,700 But there are three other comparison operators I would like to demonstrate. 5 00:00:14,720 --> 00:00:17,750 So I'm going to open up this little section here in my script. 6 00:00:17,750 --> 00:00:21,860 And here are the six comparison operators we get to use in Lua. 7 00:00:21,950 --> 00:00:28,550 You already know of the less than, greater than and equal to comparison operators, but we have a few 8 00:00:28,550 --> 00:00:36,470 others, such as less than or equal to, greater than or equal to and not equal to, and we use a tilde 9 00:00:36,470 --> 00:00:38,690 key to represent not equal. 10 00:00:38,720 --> 00:00:41,480 So to demonstrate this all I'm going to do is create a variable. 11 00:00:41,480 --> 00:00:44,420 I'm just going to call it comparison num. 12 00:00:44,690 --> 00:00:47,750 And we're going to set it equal to a value of like ten. 13 00:00:48,050 --> 00:00:49,670 Then we can create an if statement. 14 00:00:49,670 --> 00:00:52,820 So we'll type out if and then create our condition here. 15 00:00:52,820 --> 00:00:58,610 So we're going to check if our comparison number is let's say less than 50. 16 00:00:58,640 --> 00:01:03,230 So if our comparison number is less than 50 then we can print out into the console. 17 00:01:03,260 --> 00:01:06,230 The condition was truthy. 18 00:01:06,680 --> 00:01:12,950 And obviously since ten is less than 50 we should get that string printed into the console. 19 00:01:12,950 --> 00:01:13,730 So we hit run. 20 00:01:13,730 --> 00:01:14,360 There we go. 21 00:01:14,390 --> 00:01:16,160 The condition was truthy. 22 00:01:16,640 --> 00:01:21,560 However, once comparison number becomes greater than 50 and we hit run. 23 00:01:22,560 --> 00:01:27,510 As you can see, nothing gets printed out into the console because that condition evaluated to false. 24 00:01:27,960 --> 00:01:33,120 However, let's say the comparison number was exactly the value of 50. 25 00:01:33,150 --> 00:01:38,460 Well, 50 is not less than 50, so this condition would still evaluate to false. 26 00:01:38,460 --> 00:01:41,250 But what if we wanted to include the value of 50? 27 00:01:41,280 --> 00:01:46,220 Well this is where we can use the less than or equal to comparison operator. 28 00:01:46,230 --> 00:01:49,350 So what I'm going to do is put an equal sign here and there we go. 29 00:01:49,350 --> 00:01:55,550 Now it's checking if the comparison number is less than or equal to the value of 50. 30 00:01:55,560 --> 00:01:59,400 And since 50 is equal to 50 this should be true. 31 00:01:59,430 --> 00:02:01,680 We hit run and there we go. 32 00:02:01,710 --> 00:02:03,860 The condition was truthy. 33 00:02:03,870 --> 00:02:08,640 We can also check if comparison number is greater than or equal to 50. 34 00:02:08,670 --> 00:02:16,650 So if we made this value such as 51 and we hit run, of course the condition was truthy because 51 is 35 00:02:16,650 --> 00:02:23,550 greater than 50 and if we left it at 50 it would also evaluate to true because 50 is equal to 50. 36 00:02:23,790 --> 00:02:29,580 Now what if we want to check when a value is not equal to another specific value? 37 00:02:29,610 --> 00:02:37,020 For example, maybe we only want to execute this if statement when comparison number is not equal to 38 00:02:37,020 --> 00:02:37,800 ten. 39 00:02:37,800 --> 00:02:44,040 So if I put this tilde key here, we're now checking if comparison number is not equal to. 40 00:02:44,040 --> 00:02:45,810 And then we can put the value of ten here. 41 00:02:46,200 --> 00:02:52,200 So this will only execute when comparison number is not equal to ten. 42 00:02:52,200 --> 00:02:56,540 Any time the comparison number is ten this is not going to execute. 43 00:02:56,550 --> 00:02:59,940 So if I put the value of ten here and we go and run. 44 00:03:01,110 --> 00:03:06,540 As you can see, nothing gets printed in the console because ten is equal to ten. 45 00:03:06,540 --> 00:03:08,240 So this evaluated to false. 46 00:03:08,250 --> 00:03:13,200 But if we made comparison number for example like negative ten and we hit run. 47 00:03:13,970 --> 00:03:18,860 As you can see, the condition was truthy because negative ten is not equal to ten. 48 00:03:19,830 --> 00:03:23,370 We can also make this a big number like like that. 49 00:03:23,370 --> 00:03:24,450 And then we hit run. 50 00:03:24,450 --> 00:03:30,120 And of course the condition was truthy because that big number is not equal to ten. 51 00:03:30,660 --> 00:03:36,240 So this was just a brief overview of the comparison operators you will be using in the conditions for 52 00:03:36,240 --> 00:03:37,270 your if statements. 53 00:03:37,290 --> 00:03:39,330 I will see you in the next one.